package com.vallis.statis;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author guozh
 * @Classname CalcActivity
 * @Description TODO
 * @Date 2020年12月6日, 0006 21:50:09
 * @Created by vallis
 */
@Data
@AllArgsConstructor
public class CalcActivity implements Runnable{
    
    private volatile int current;
    private int amount;
    
    private List<LotteryTicket> vData;
    private int vType;
    private List<LotteryOutPut> lotteryOutPuts;
    @Override
    public void run() {
        calcByTrue();
    }
    
    
    
    /**
     * 实际数据 N+0 或0+N
     * 票面数据：
     *      1+0：1
     *      2+0：2
     *      3+0：3
     *      4+0：4
     *      5+0：5
     *      6+0：6
     *      0+1：7
     *      0+2：8
     *
    
     * @return
     */
    public  List<LotteryOutPut> calcByTrue(){
       
        //新建输入内容
        lotteryOutPuts=new ArrayList<>();
        //N+0集合或0+N
        List<String[]> typeList=new ArrayList<>();
        //去重用 n+0票
        List<LotteryTicket> typeTemp=new ArrayList<>();
        this.current=0;
        vData.forEach(item->{
                    //分解成标准的5+2形式
                    List<LotteryTicket> decomposed = LotteryUtil.decomposed(item);
                    decomposed.forEach(item2->{
                        if (vType<7){
                            List<String[]> strings = LotteryUtil.decomposedFront(item2,vType);
                            typeList.addAll(strings);
                        }else if(vType==7){
                            List<String[]> strings = LotteryUtil.decomposedEnd(item2,1);
                            typeList.addAll(strings);
                        }else if (vType==8){
                            List<String[]> strings = LotteryUtil.decomposedEnd(item2,2);
                            typeList.addAll(strings);
                        }
                    });
                }
        );
        this.current=20;
        //此时typeList 已经装满，生成对应的LotteryTicket,目的是为了去重
        
        typeList.forEach(item->{
            LotteryTicket lotteryTicket=new LotteryTicket(Arrays.toString(item),Arrays.toString(item),LotteryUtil.stringArrayToInt(item),LotteryUtil.stringArrayToInt(item));
            //添加入一个临时集合
            typeTemp.add(lotteryTicket);
            
            
        });
        
        List<LotteryTicket> distinct = LotteryUtil.distinct(typeTemp);
        System.out.println("临时结合去重前大小"+typeTemp.size());
        System.out.println("临时集合：");
        distinct.forEach(System.out::println);
        //将临时集合中的每一个LotteryTicket 转换成输入内容
        this.current=50;
        distinct.forEach(item->{
            //将输出内容转换成String[]
            if (vType<7){
                String[] strings = LotteryUtil.intArrayToString(item.getFrontNumArray());
                //新建一个输出内容
                LotteryOutPut lotteryOutPut=new LotteryOutPut(strings);
                //计算出现的次数
                lotteryOutPut.setTimes(LotteryUtil.frequency(typeList,strings));
                lotteryOutPut.setType(vType);
                //添加至输出内容
                lotteryOutPuts.add(lotteryOutPut);
            }else if (vType==7){
                String[] strings = LotteryUtil.intArrayToString(item.getEndNumArray());
                //新建一个输出内容
                LotteryOutPut lotteryOutPut=new LotteryOutPut(strings);
                //计算出现的次数
                lotteryOutPut.setTimes(LotteryUtil.frequency(typeList,strings));
                lotteryOutPut.setType(vType);
                //添加至输出内容
                lotteryOutPuts.add(lotteryOutPut);
            }else if (vType==8){
                String[] strings = LotteryUtil.intArrayToString(item.getEndNumArray());
                //新建一个输出内容
                LotteryOutPut lotteryOutPut=new LotteryOutPut(strings);
                //计算出现的次数
                lotteryOutPut.setTimes(LotteryUtil.frequency(typeList,strings));
                lotteryOutPut.setType(vType);
                //添加至输出内容
                lotteryOutPuts.add(lotteryOutPut);
            }
            
            
        });
        this.current=70;
//        System.out.println("实际数据：");
//        System.out.println(lotteryOutPuts.size());
//        lotteryOutPuts.forEach(System.out::println);
        this.lotteryOutPuts=lotteryOutPuts;
        return lotteryOutPuts;
    }
    
  
}
